<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Clearfix</title>
    <style>
        .clearfix:after {
            content: '';
            display: block;
            clear: both;
        }

        .clearfix {
            *zoom: 1;
            /* 兼容IE */
        }

        .container {
            width: 100%;
            background-color: black;
            border: 3px solid rebeccapurple;
        }

        .left {
            width: 200px;
            height: 300px;
            background-color: lightcoral;
            float: left;
        }

        .footer {
            width: 100%;
            height: 50px;
            background-color: lightgray;
        }

        .container1 {
            width: 100%;
            background-color: black;
            border: 3px solid rebeccapurple;
        }

        .left1 {
            width: 200px;
            height: 300px;
            background-color: lightcoral;
            float: left;
        }

        .footer1 {
            width: 100%;
            height: 50px;
            background-color: lightgray;
        }
    </style>
</head>

<body>
    <fieldset>
        <legend>子元素folat后脱离文档流，不能撑起父元素container高度，footer位置移到container位置</legend>
        <div class="container1">
            <div class="left1">left</div>
        </div>
        <div class="footer1">footer</div>
    </fieldset>
    <fieldset>
        <legend>父元素增加clearfix</legend>
        <div class="container   clearfix">
            <div class="left">left</div>
        </div>
        <div class="footer">footer</div>
    </fieldset>
</body>

</html>